package com.xy.annotaion.handler.kotlin.pdf

import com.itextpdf.io.image.ImageDataFactory
import com.itextpdf.kernel.pdf.PdfDocument
import com.itextpdf.kernel.pdf.PdfWriter
import com.itextpdf.layout.Document
import com.itextpdf.layout.element.AreaBreak
import com.itextpdf.layout.element.Image
import com.itextpdf.layout.property.AreaBreakType
import com.xy.annotaion.handler.kotlin.p

fun main() {

    val pdf = PdfDocument(PdfWriter("image.pdf"))
    val doc = Document(pdf)
    val pics = arrayOf("readme/vim1.jpg", "readme/vim2.jpg", "readme/vim3.jpg", "readme/vim4.jpg")

    for (i in pics) {
        val img = Image(ImageDataFactory.create(i))
        img.setAutoScaleWidth(true)
        img.setAutoScaleHeight(true)
//        val p = pdf.addNewPage()
//        p.flush()
//        val doc = Document(p.document)
        doc.add(img)
        //换页
        doc.add(AreaBreak(AreaBreakType.NEXT_PAGE));

//        doc.close()

    }
    pdf.close()


    p("add images to pdf over")


}